
const mysql = require('mysql')

module.exports = {

  createConnection() {
    return mysql.createConnection({
      host: '47.105.219.243',
      port: '3306',
      user: 'root',
      password: '7Rbf5LLjwfUP5Yxx',
      database: 'bebeelee'
    })
  },

  query(sql, params = null) {
    return new Promise(( resolve, reject ) => {
      let connection = this.createConnection()

      connection.connect()
      connection.query(sql, params, (err, rows) => {
        if(err) {
          reject(err)
        } else {
          resolve(rows)
        }
      })
      connection.end()
    })
  }
}
